﻿using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using BasicInformation.ReadAPI.Application.Command.LineCommand;
using MediatR;

namespace BasicInformation.ReadAPI.Application.CommandHandler.LineCommandHandler
{
    public class LineRouteListCommandHandler : IRequestHandler<LineRouteListCommand, List<LineSelect>>
    {
        private readonly ILineRepository lineRepository;

        public LineRouteListCommandHandler(ILineRepository lineRepository)
        {
            this.lineRepository = lineRepository;
        }

        public async Task<List<LineSelect>> Handle(LineRouteListCommand request, CancellationToken cancellationToken)
        {
            var list = await lineRepository.GetList();
            List<LineSelect> res = new List<LineSelect>();
            foreach (var line in list)
            {
                res.Add(new LineSelect
                {
                    Id = line.Id,
                    Name = line.LineName,
                    Qaddress=line.OriginAddress,
                    Address = line.EndPointAddress,
                });
            }
            return res;
        }
    }
}
